# generate protobuf sources
file(GLOB proto_files proto/*.proto)
caffe_protobuf_generate_cpp_py(${proto_gen_folder} proto_srcs proto_hdrs proto_python ${proto_files})

# include python files either to force generation
add_library(proto STATIC ${proto_hdrs} ${proto_srcs} ${proto_python})
set(Caffe_LINKER_LIBS proto ${Caffe_LINKER_LIBS}) # note, crucial to prepend!
caffe_default_properties(proto)

# --[ Caffe library

# creates 'test_srcs', 'srcs', 'test_cuda', 'cuda' lists
caffe_pickup_caffe_sources(${PROJECT_SOURCE_DIR})

# Use C++11 for some things...
set(MY_CXX_FLAGS "  -std=c++11 ")
set_source_files_properties(layers/hand_data_layer.cpp PROPERTIES COMPILE_FLAGS ${MY_CXX_FLAGS})
set_source_files_properties(layers/mv_regression_loss.cpp PROPERTIES COMPILE_FLAGS ${MY_CXX_FLAGS})
set_source_files_properties(jvl.cpp PROPERTIES COMPILE_FLAGS ${MY_CXX_FLAGS})
set_source_files_properties(ThreadPool.cpp PROPERTIES COMPILE_FLAGS ${MY_CXX_FLAGS})

if(HAVE_CUDA)
  caffe_cuda_compile(cuda_objs ${cuda})
  list(APPEND srcs ${cuda_objs} ${cuda})
endif()

FIND_PACKAGE( Boost COMPONENTS REQUIRED system filesystem thread regex)
add_library(caffe ${srcs})
target_link_libraries(caffe proto ${Caffe_LINKER_LIBS} ${Boost_LIBRARIES})
caffe_default_properties(caffe)

# ---[ Tests
 add_subdirectory(test)

# ---[ Install
install(DIRECTORY ${Caffe_INCLUDE_DIR}/caffe DESTINATION include)
install(FILES ${proto_hdrs} DESTINATION include/caffe/proto)
install(TARGETS caffe proto EXPORT CaffeTargets DESTINATION lib)

file(WRITE ${PROJECT_BINARY_DIR}/__init__.py)
list(APPEND proto_python ${PROJECT_BINARY_DIR}/__init__.py)
install(PROGRAMS ${proto_python} DESTINATION python/caffe/proto)


